/*
 * UART.c
 *
 *  Created on: 6.11.2012
 *      Author: Z183797
 */
#include "UART.h"
#include <avr/io.h>
#include <avr/interrupt.h>


/*
 * initUART
 *  - inicializace UART (nastaveni prislusnych registru)
 */
void initUART()
{
    UCSRA|=0x00;
    UBRRL|=0x0C;
    UCSRB|=0x18;  // povolit vysilani a prijem
    UCSRC|=0x86;  // ramec dat:  8 datovych, 1 stop bit, bey parity
    UCSRB |= (1 << RXCIE);// Interrupt od UART RXC
}

/*
 * readUart
 *  - cteni znaku z UART
 */
unsigned char readUART(void)
{
        while(!(UCSRA&0x80))
     ;
    return UDR;
}

/*
 * writeCharacter
 *  - zapis znaku na UART
 */
void writeCharacter(const char znak)
{
        while (!(UCSRA&0x20))
    ;
    UDR = znak;
}

/*
 * writeUART
 *  - zapis Stringu
 */
void writeUART (const char *text)
{
        while (*text)
        {
        	writeCharacter(*(text++));
        }
}
